home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-10-08 | 4.8 KB | 131 lines | [TEXT/ALFA] |
-
- #############################################################################
- # FILE: sql.tcl
- #----------------------------------------------------------------------------
- # AUTHOR: Joel D. Elkins
- # of New Media, Inc.
- # 200 South Meridian, Ste. 220
- # Indianapolis, IN 46225
- #
- # internet: jdelkins@iquest.net (preferred)
- # compuserve: 72531,314
- # AOL: jdelkins
- #
- # Copyright © 1994-1995 by Joel D. Elkins
- # All rights reserved.
- #############################################################################
- #
- # Alpha mode for SQL and Oracle's PL/SQL programming language
- # Converts SQL and PL/SQL keywords to uppercase on the fly and colorizes
- #
- #############################################################################
- # HISTORY
- #
- # modified who rev reason
- # -------- --- --- ------
- # 7/29/94 JDE 1.0 Original
- # 2/8/95 JDE 1.1 Added electUpper for tab, cr, and ';'
- #############################################################################
-
- alpha::mode SQL 1.0 dummySQL { *.sql *.SQL *.pkg}
-
- proc dummySQL {} {}
-
- #############################################################################
- # PL/SQL mode by Joel D. Elkins
- #############################################################################
- newPref f elecRBrace {0} SQL
- newPref f electricSemi {1} SQL
- newPref v wordBreak {(\$)?\w+} SQL
- newPref v prefixString {--} SQL
- newPref f elecLBrace {0} SQL
- newPref f wordWrap {0} SQL
- newPref v funcExpr {(PROCEDURE|FUNCTION)[ \t]+(\w+)} SQL
- newPref v wordBreakPreface {[^a-zA-Z0-9_\$]} SQL
-
- bind '\ ' {electUpper "\ "} "SQL"
- bind '\t' {electUpper "\t"} "SQL"
- bind '\r' {electUpper "\r"} "SQL"
- bind '\;' {electUpper "\;"} "SQL"
-
-
- set sqlKeywords {
- ABORT ACCEPT ACCESS ALTER AND ARRAY ARRAYLEN AS ASSERT AT AVG BEGIN BETWEEN BODY
- CASE COLUMNS COMMIT CONSTANT COUNT CREATE CURSOR DECLARE DEFAULT DEFINITION
- DELETE DESC DISPOSE DISTINCT DO DROP ELSE ELSIF END ENTRY EXCEPTION EXISTS EXIT
- FALSE FETCH FOR FROM FUNCTION GOTO IF IN INSERT INTERSECT INTO IS LIKE LOOP MAX MIN
- MINUS MOD NEW OF ON OPEN OR OUT PACKAGE PARTITION POSITIVE PRAGMA PRIVATE
- PROCEDURE PUBLIC RANGE RECORD REM REPLACE RETURN ROLLBACK ROWTYPE RUN SAVEPOINT
- SELECT SET SIZE START STDDEV SUM THEN TO TYPE UNION UNIQUE UPDATE USE VALUES
- VARIANCE WHEN WHERE WHILE WITH XOR
- }
- ### Just colorize uppercase keywords
- # abort accept access alter and array arraylen as assert at avg begin between body
- # case columns commit constant count create cursor declare default definition
- # delete desc dispose distinct do drop else elsif end entry exception exists exit
- # false fetch for from function goto if in insert intersect into is like loop max min
- # minus mod new of on open or out package partition positive pragma private
- # procedure public range record rem replace return rollback rowtype run savepoint
- # select set size start stddev sum then to type union unique update use values
- # variance when where while with xor
- ###
- regModeKeywords -e {--} -b {/*} {*/} -c red -k blue SQL $sqlKeywords
- unset sqlKeywords
- #================================================================================
-
- catch {unset plSqlKeywords}
-
- lappend plSqlKeywords \
- abort accept access alter and array arraylen as assert at avg begin between body \
- case columns commit constant count create cursor declare default definition \
- delete desc dispose distinct do drop else elsif end entry exception exists exit \
- false fetch for from function goto if in insert intersect into is like loop max min \
- minus mod new of on open or out package partition positive pragma private \
- procedure public range record rem replace return rollback rowtype run savepoint \
- select set size start stddev sum then to type union unique update use values \
- variance when where while with xor
-
-
- proc electUpper {char} {
- global plSqlKeywords
-
- set a [getPos]
- backwardWord
- set b [getPos]
-
- #make sure we're not in a comment
- beginningOfLine
- set commentSearch {(^[ \t]*rem[ \t]+)|(^[ \t]*REM[ \t]+)|--}
- if {[catch {search -s -r 1 -f 1 -l $b -- $commentSearch [getPos]}] != 0} {
- #if not, make the word uppercase if it's a keyword
- set cmd [getText $b $a]
- goto $b
- if {[lsearch -exact $plSqlKeywords [string tolower $cmd]] >= 0} {
- upcaseWord
- }
- }
- goto $a
- if { 0 == [string compare $char "\r"] } {
- bind::CarriageReturn
- } else {
- insertText $char
- }
- }
-
- proc SQL::MarkFile {} {
- global SQLmodeVars
- set pos 0
- while {![catch {search -s -f 1 -r 1 -m 0 -i 0 $SQLmodeVars(funcExpr) $pos} res]} {
- set start [lindex $res 0]
- set end [lindex $res 1]
- set text [lindex [getText $start $end] 1]
- set pos $end
- set inds($text) "$start $end"
- }
-
- if {[info exists inds]} {
- foreach f [lsort [array names inds]] {
- setNamedMark $f [lineStart [lineStart [lindex $inds($f) 0]] - 1] [lindex $inds($f) 0] [lindex $inds($f) 1]
- }
- }
- }